package de.openlaboratory.labhub.core;

import javax.ejb.SessionBean;
import javax.servlet.ServletRequest;

import com.sun.servicetag.Registry;

import de.openlaboratory.labhub.core.framework.LabHubApplication;

public class ApplicationResources
{
	private static ApplicationResources instance = null;

	public static ApplicationResources getInstance()
	{
		if (instance == null)
		{
			instance = new ApplicationResources();
		}
		return instance;
	}

	public String getMessageAttr()
	{
		// TODO Auto-generated method stub
		return "app_msg";
	}

	public String getErrorPage(Exception e)
	{
		return "Error: " + e.getMessage();
	}

	public static SessionBean getRegistryService()
	{
		// TODO Auto-generated method stub
		Registry.getSystemRegistry();
		return null;
	}

	public static LabHubApplication getLabHubApplication(ServletRequest request) {
		// TODO Extract Application name

		String applicationName = "console";

		String applicationClass = "de.openlaboratory.labhub.core.server.console";

		LabHubApplication app = null;
		Class<?> c;

		try {
			c = Class.forName(applicationClass);
			app = (LabHubApplication) c.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return app;
	}
}
